home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / tools / ebsx130 / jisconv2.c < prev    next >
Text File  |  1997-05-07  |  11KB  |  462 lines

  1. /* kenji suzuki */
  2. /* JIS to shift-JIS converter for 広辞苑 */
  3.  
  4. #include "common2.h"
  5.  
  6. #include <iocslib.h>
  7. /* #include <stdio.h> */
  8. #include <method\Dos_i.h>
  9.  
  10. int    steps;        /* kenji suzuki */
  11. unsigned short    gra_x;    /* kenji suzuki  */
  12. unsigned short    gra_y;    /* kenji suzuki  */
  13.  
  14.  
  15. static    unsigned int get_int( void )
  16. {
  17.     unsigned int c;
  18.  
  19.     DOSREAD( cdfile , &c     , sizeof( unsigned int ) );
  20.     steps+=4;
  21.  
  22.     return( c );
  23. };
  24.  
  25. static    unsigned short get_short( void )
  26. {
  27.     unsigned short c;
  28.  
  29.     DOSREAD( cdfile , &c     , sizeof( unsigned short ) );
  30.     steps+=2;
  31.  
  32.     return( c );
  33. };
  34.  
  35. static    unsigned char get_char( void )
  36. {
  37.     unsigned char c;
  38.  
  39.     DOSREAD( cdfile , &c     , sizeof( unsigned char ) );
  40.     steps++;
  41.  
  42.     return( c );
  43. };
  44.  
  45. static    int jis2ank(int c)
  46. {
  47.     int    ch,cc;
  48.     ch=c&0xff;
  49.     cc=0xffff0000+'?';
  50.     if ((c&0x2300)==0x2300) {
  51.         cc=ch;
  52.     } else if ((c&0x2100)==0x2100) {
  53.         switch (ch) {
  54.             case 0x21: cc=' '; break;
  55.             case 0x27: cc=':'; break;
  56.             case 0x28: cc=';'; break;
  57.             case 0x29: cc='?'; break;
  58.             case 0x2a: cc='!'; break;
  59.             case 0x3c:
  60.             case 0x3d:
  61.             case 0x3e: cc='-'; break;
  62.             case 0x3f: cc='/'; break;
  63.             case 0x5c: cc='+'; break;
  64.             case 0x5d: cc='-'; break;
  65.             case 0x70: cc='$'; break;
  66.             case 0x73: cc='%'; break;
  67.             case 0x74: cc='#'; break;
  68.             case 0x75: cc='&'; break;
  69.             case 0x76: cc='*'; break;
  70.             case 0x77: cc='@'; break;
  71.             case 0x7e: cc='  '; break;
  72.         }
  73.     }
  74.     return cc;
  75. }
  76.  
  77. /* original char* jis2shift(jischar *str , char *op, size_l length, int type) */
  78. int jis2shift(char *op, size_l length, int type , int *nextflg )
  79. {
  80.     int    code;    /* kenji suzuki */
  81.     jischar    c,ch;
  82.     int    k;
  83.     char    *p=op;
  84.     char    zenkaku=1;
  85.     jischar s1,s2,s3,s4;    /* kenji suzuki */
  86.     int    count;        /* kenji suzuki */
  87.     unsigned char flg;
  88.     unsigned char cb;
  89.     unsigned char ccode;
  90.  
  91.     int cnt;
  92.     int endflg;
  93.     unsigned short arw = '◎';
  94.  
  95.     /* 97/5/1 epwing */
  96.     int indexnum;
  97.     unsigned char num , num2;
  98.     unsigned int  wk;
  99.  
  100.     *nextflg = 1;
  101.     steps = 0;
  102.     endflg = 0;
  103.  
  104. /*
  105.     c = get_short( );
  106.     DOSSEEK( cdfile , -2 , SEEK_CUR );
  107. */
  108.     for (;;) {
  109. /* kenji suzuki */
  110.         if( e_key == 0 )
  111.         {
  112.             c = get_short( );
  113.             cb = (unsigned char)( c >> 8 );
  114.             flg = ( c & 0x00ff );
  115.         } else {
  116.             cb = get_char( );
  117.         };
  118. /* original    c=*str++; */
  119.         if (cb==0x1f) {
  120.             if( e_key == 1 )
  121.             {
  122.                 flg = get_char( );
  123.             };
  124.             switch (flg) {
  125.                 case 0x02: break;
  126.                 case 0x03: 
  127.                     *nextflg = 0;
  128.                     *p++=0;
  129.                     return steps;
  130.                 case 0x04:
  131.                     zenkaku=0; break;
  132.                 case 0x05:
  133.                     zenkaku=1; break;
  134. /* kenji suzuki */        case 0x06:
  135.                     break;
  136. /* kenji suzuki */        case 0x07:
  137.                     break;
  138.                 case 0x09:
  139. /* kenji suzuki */
  140.                     c = get_short( );
  141. /* original                c=*str++;
  142.                     if(c!=1&&c!=5)printf("(1f09:%x)",c); */
  143.                     if (c==1) {
  144.                         if( endflg == 0 )
  145.                         {
  146.                             endflg = 9;    /* 最初にみつかった物は無視 */
  147.                         } else if( endflg == 9 )
  148.                         {
  149.                             *p++=0;
  150.                             return steps-4;    /* 2番目でリターン */
  151.                         };
  152.                     }
  153.                     break;
  154.                 case 0x0a:
  155. /* original                if (type!=0) { */
  156. /* kenji suzuki */            if (type==0) {
  157.                         *p++=0x0d, *p++=0x0a;
  158.                         break;
  159.                     }
  160.                     *p++=0;
  161.                     return steps;
  162. /* kenji suzuki */        case 0x0e:
  163.                     break;
  164. /* kenji suzuki */        case 0x0f:
  165.                     break;
  166. /* kenji suzuki */        case 0x10:
  167.                     break;
  168. /* kenji suzuki */        case 0x11:
  169.                     break;
  170.                 case 0x41:        /* ポイントの切りかえ? */
  171. /* kenji suzuki */
  172.                     if( endflg == 0 )
  173.                     {
  174.                         c = get_short( );
  175.                         endflg = 41;    /* 最初にみつかった物は無視 */
  176.                     } else if( endflg == 41 )
  177.                     {
  178.                         *p++=0;
  179.                         return steps-2;    /* 2番目でリターン */
  180.                     } else {
  181.                         c = get_short( );
  182.                     };
  183. /* original                *str++; */
  184.                     break;
  185.                 case 0x61:        /* ポイントを元に戻す? */
  186.             /*        *p++ = (char)((arw & 0xff00) >> 8);
  187.                     *p++ = (char)arw & 0x00ff;
  188.         */    /*        *p++='(',*p++='6',*p++='1',*p++=')';
  189.             */        break;
  190.                 case 0x42:
  191.                     *p++ = (char)((arw & 0xff00) >> 8);
  192.                     *p++ = (char)arw & 0x00ff;
  193.                     push_link_a( 3 , p-op-2 );
  194.                     break;
  195.                 case 0x62:
  196. /* kenji suzuki 参照 */
  197.                     indexpage = get_int( );
  198.                     c = get_short( );
  199.                     indexoff = (unsigned int)c;
  200.                     indexpage = conv_hex( indexpage );
  201.                     indexoff = conv_hex( indexoff );
  202.  
  203.                     push_link_b( ((indexpage-1)*0x800)+indexoff );
  204.  
  205. /* kenji suzuki             printf("(%x:%x,%x,%x)",c,s1,s2,s3); */
  206.  
  207. /* original                printf("(%x:%x,%x,%x)",c,*str,*(str+1),*(str+2));
  208.                     str+=3;
  209.                     *p++='(',*p++='6',*p++='2',*p++=')';
  210. */
  211.                     break;
  212.                 case 0x43:
  213.                     *p++ = (char)((arw & 0xff00) >> 8);
  214.                     *p++ = (char)arw & 0x00ff;
  215.                     push_link_a( 2 , p-op-2 );
  216.                     break;
  217.                 case 0x63:
  218. /* kenji suzuki メニュー */
  219.                     indexpage = get_int( );
  220.                     c = get_short( );
  221.                     indexoff = (int)c;
  222.                     indexpage = conv_hex( indexpage );
  223.                     indexoff = conv_hex( indexoff );
  224.                     push_link_b( ((indexpage-1)*0x800)+indexoff );
  225.  
  226.                     break;
  227. /* kenji suzuki */        case 0x45:
  228.                     c = get_short( );
  229.                     count = 0;
  230.                     break;
  231. /* kenji suzuki */        case 0x65:
  232.                     break;
  233. /* kenji suzuki */        case 0x31:    /* サイズ */
  234.                     c = get_short( );
  235.                     gra_x = get_short( );
  236.                     gra_y  = get_short( );
  237.                     break;
  238. /* kenji suzuki */        case 0x51:
  239.                     break;
  240. /* kenji suzuki */        case 0x32:
  241.                     *p++ = (char)((arw & 0xff00) >> 8);
  242.                     *p++ = (char)arw & 0x00ff;
  243.                     push_link_a( 1 , p-op-2 );
  244.                     break;
  245. /* kenji suzuki グラフィック? */    case 0x52:
  246.                     indexpage = get_int( );
  247.                     c = get_short( );
  248.                     indexoff = (int)c;
  249.                     indexpage = conv_hex( indexpage );
  250.                     indexoff = conv_hex( indexoff );
  251.  
  252.                     push_link_b( ((indexpage-1)*0x800)+indexoff );
  253.                     break;
  254. /* kenji suzuki 音声? */    case 0x33:    /* ファイル型? */
  255.             /*        *p++ = (char)((arw & 0xff00) >> 8);
  256.                     *p++ = (char)arw & 0x00ff;
  257.             */        break;
  258. /* kenji suzuki */        case 0x53:
  259.                     DOSREAD( cdfile , &c  , sizeof( unsigned short ) );
  260.                     DOSREAD( cdfile , &s1 , sizeof( unsigned short ) );
  261.                     DOSREAD( cdfile , &s2 , sizeof( unsigned short ) );
  262.                     DOSREAD( cdfile , &s3 , sizeof( unsigned short ) );
  263.                     steps+=8;
  264.                     break;
  265. /* kenji suzuki 音声? */    case 0x34:    /* トラック型? */
  266.             /*        *p++ = (char)((arw & 0xff00) >> 8);
  267.                     *p++ = (char)arw & 0x00ff;
  268.             */        break;
  269. /* kenji suzuki */        case 0x54:
  270.                     indexpage = get_short( );
  271.                     DOSREAD( cdfile , &s1 , sizeof( unsigned short ) );
  272.                     DOSREAD( cdfile , &s2 , sizeof( unsigned short ) );
  273.                     DOSREAD( cdfile , &s3 , sizeof( unsigned short ) );
  274.                     steps+=6;
  275.                     break;
  276.  
  277. /* 97/5/1 epwing */
  278.                 case 0x0b:
  279.                     break;
  280.                 case 0x0c:
  281.                     break;
  282.                 case 0x14:
  283.                     DOSSEEK( cdfile , 4 , SEEK_CUR );
  284.                     break;
  285.                 case 0x15:
  286.                     break;
  287. /* サイズ */            case 0x44:
  288.                     c = get_short( );
  289.                     wk = get_int( );
  290.                     gra_y = conv_hex( wk );
  291.                     wk = get_int( );
  292.                     gra_x = conv_hex( wk );
  293.                     *p++ = (char)((arw & 0xff00) >> 8);
  294.                     *p++ = (char)arw & 0x00ff;
  295.                     push_link_a( 4 , p-op-2 );
  296.                     break;
  297. /* グラフィック */        case 0x64:
  298.                     indexpage = get_int( );
  299.                     c = get_short( );
  300.                     indexoff = (unsigned int)c;
  301.                     indexpage = conv_hex( indexpage );
  302.                     indexoff = conv_hex( indexoff );
  303.  
  304.                     push_link_b( ((indexpage-1)*0x800)+indexoff );
  305.                     break;
  306.                 case 0x47:
  307.                     break;
  308. /*  */                case 0x67:
  309.                     indexnum = 0;
  310.                     num = get_char( );
  311.                     while( num == 0x1e )
  312.                     {
  313.                         num2 = get_char( );
  314.                         indexnum = (indexnum*10) + conv_hex( (int)num2 );
  315.                         num = get_char( );
  316.                     };
  317.                     DOSSEEK( cdfile , -1 , SEEK_CUR );
  318.                     steps--;
  319.                     break;
  320.                 case 0x4a:
  321.                     DOSSEEK( cdfile , 16 , SEEK_CUR );
  322.                     break;
  323.                 case 0x6a:
  324.                     break;
  325.                 case 0x4d:
  326.                     DOSSEEK( cdfile , 18 , SEEK_CUR );
  327.                     break;
  328.                 case 0x6d:
  329.                     break;
  330. /* 0d,12,13,4b,4c,6b,6cは */    case 0x0d:
  331. /* 実際には見たことはない */        break;
  332. /* けど一応入れておく */    case 0x12:
  333.                     break;
  334.                 case 0x13:
  335.                     break;
  336.                 case 0x4b:
  337.                     break;
  338.                 case 0x6b:
  339.                     break;
  340.                 case 0x4c:
  341.                     break;
  342.                 case 0x6c:
  343.                     break;
  344.  
  345.                 default:
  346. /* kenji suzuki */
  347.                     DOSREAD( cdfile , &c , sizeof( unsigned short ) );
  348.                     DOSREAD( cdfile , &s1 , sizeof( unsigned short ) );
  349.                     DOSREAD( cdfile , &s2 , sizeof( unsigned short ) );
  350.                     DOSREAD( cdfile , &s3 , sizeof( unsigned short ) );
  351.                     DOSREAD( cdfile , &s4 , sizeof( unsigned short ) );
  352.                     steps+=10;
  353. /*                    printf("(%x:%x,%x,%x,%x)",c,s1,s2,s3,s4); */
  354. /* original                printf("[%x,%x,%x,%x,%x]",
  355.                         c,*str,*(str+1),*(str+2),*(str+3)); */
  356.                     *p++=0;
  357.                     return steps;
  358.             }
  359.         } else {
  360. /* orignal        if (c==0xa169) ch=k=0x8391;  */  /* 'ヱ' */
  361. /* orignal        else if (c==0xa168) ch=k=0x8390;  */  /* 'ヰ' */
  362.  
  363.             if( e_key == 0 )
  364.             {
  365.  
  366. /* kenji suzuki */        if( c >= f1jisst && c <= f1jised )
  367. /* 全角外字の表示 */             {
  368.                     ch = 0;
  369.                     if( c <= f1jismax )
  370.                     {
  371.                         if( c >= f1jisst+0x100 )
  372.                             code = c - ( f1jisst+0x100 ) + 94;
  373.                         else
  374.                             code = c - f1jisst;
  375.                         *p++ = (char)( codetbl1[ code ] >> 8 );
  376.                         *p++ = (char)( codetbl1[ code ] & 0x00ff );
  377.                     } else {
  378.                         *p++ = ' ';
  379.                         *p++ = ' ';
  380.                     };
  381.                      }
  382. /* kenji suzuki */        else if( c >= f2jisst && c <= f2jised )
  383. /* 半角外字の表示 */             {
  384.                     ch = 0;
  385.                     if( c <= f2jismax )
  386.                     {
  387.                         if( c >= f2jisst+0x100 )
  388.                             code = c - ( f2jisst+0x100 ) + 94;
  389.                         else
  390.                             code = c - f2jisst;
  391.                         *p++ = (char)( codetbl2[ code ] >> 8 );
  392.                         *p++ = (char)( codetbl2[ code ] & 0x00ff );
  393.                     } else {
  394.                         *p++ = ' ';
  395.                         *p++ = ' ';
  396.                     };
  397.                      }
  398.                 else if (0xb536<=c&&c<=0xb545) {
  399.                     ch=0;
  400.                     *p++='(';
  401.                     if (c>0xb536+9-1) *p++='1';
  402.                     *p++=((c-0xb536+1)%10)+'0';
  403.                     *p++=')';
  404.                 } else ch=k=JISSFT(c);
  405.     /*            if (k<0) {
  406.                     printf(":%4x.%4x:",*(str-2),c);
  407.                     ch=('?'<<8)+'?';
  408.                 }
  409.     */
  410.             } else {
  411.                  if( cb == f2esc  )        /* 範囲はこれで良いのか */
  412. /* 半角外字の表示 */        {
  413.                     ch = 0;
  414.                     ccode = get_char( );
  415.                     if( ccode <= f2ascmax )
  416.                     {
  417.                         *p++ = (char)( codetblebg[ ccode ] >> 8 );
  418.                         *p++ = (char)( codetblebg[ ccode ] & 0x00ff );
  419.                     } else {
  420.                         *p++ = ' ';
  421.                     };
  422.                 } 
  423.                 else if( cb >= 0x80 )    /* 0x80以上はどんな文字か判らないのでスペースを表示 */
  424.                 {
  425.                     ch = ' ';
  426.                 } else {
  427.                     ch = cb;
  428.                 };
  429.             };
  430.             if (ch) {
  431.                 if( e_key == 0 )
  432.                 {
  433.                     if (!(c==0x2121 ||(c&0xff00)==0x2300) || zenkaku) {
  434.                         *p++=ch>>8;
  435.                         *p++=ch;
  436.                     } else {
  437.                         *p++=jis2ank(c);
  438.                     };
  439.                 } else {
  440.                     *p++=ch;
  441.                 }
  442.             }
  443.         }
  444.     }
  445. }
  446.  
  447. /*
  448. #include <stdio.h>
  449. wchar    instr[50000];
  450. char    outstr[100000];
  451. int main(int argc, char *argv[])
  452. {
  453.     FILE    *fp;
  454.     char    *cp;
  455.     fp=fopen(argv[1],"r"); if (fp==NULL) return 1;
  456.     DOSREAD(instr,1,sizeof(instr),fp);
  457.     jis2shift(instr,outstr,sizeof(outstr));
  458.     cp=outstr;
  459.     while ( *cp ) putchar(*cp++);
  460. }
  461. */
  462.